<template>
  <div id="app">
    <van-nav-bar
      :title="title"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <router-view></router-view>
    <!-- footer -->
    <van-tabbar
      v-model="active"
      active-color="#ee0a24"
      inactive-color="#000"
    >
      <van-tabbar-item
        icon="home-o"
        to="/home"
      ></van-tabbar-item>
      <van-tabbar-item
        icon="search"
        to="/search"
      ></van-tabbar-item>
      <van-tabbar-item
        icon="friends-o"
        to="/friend"
      ></van-tabbar-item>
      <van-tabbar-item
        icon="cart-o"
        to="cart"
        badge="6"
      ></van-tabbar-item>
    </van-tabbar>
  </div>
</template>
<script>
export default {
  data() {
    return {
      title: localStorage.title || 'home',
      active: Number(localStorage.active) || '0'
    }
  },
  methods: {
    onClickLeft() {
      // 编程时路由
      this.$router.go(-1)
    }
  },
  watch: {
    '$route.meta'(meta) {
      this.title = meta.title
      localStorage.title = this.$route.meta.title
      localStorage.active = this.$route.meta.active
    }
  }
}
</script>
<style>
</style>
